# Estimator的核心想法就是：把工作网络封装成一个类，训练、评估、预测都是类方法。

# 在这种封装里面，首先隐藏了网络结构，对于程序运行者，只需要考虑输入输出。
# 同时，包含了对参数数据的保存、对训练状态的保存，使得训练过程可复现，可追溯。其数据的管理，交给了Dataset，
# 在进一步了解Dataset后，二者的协作会使得编写tensorflow程序变得井井有条
import numpy as np
import tensorflow as tf
def input_evaluation_set():
    features = {'SepalLength': np.array([6.4, 5.0]),
                'SepalWidth':  np.array([2.8, 2.3]),
                'PetalLength': np.array([5.6, 3.3]),
                'PetalWidth':  np.array([2.2, 1.0])}
    labels = np.array([2, 1])
    return features, labels
def train_input_fn(features, labels, batch_size):
    """An input function for training"""
    # Convert the inputs to a Dataset.
    dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))

    # Shuffle, repeat, and batch the examples.
    return dataset.shuffle(1000).repeat().batch(batch_size)

# input_evaluation_set()

# Feature columns describe how to use the input.
train_x = {}
my_feature_columns = []
for key in train_x.keys():
    my_feature_columns.append(tf.feature_column.numeric_column(key=key))

# 我们要使用的模型函数具有以下调用签名：
def my_model_fn(
    features, # This is batch_features from input_fn
    labels,   # This is batch_labels from input_fn
    mode,     # An instance of tf.estimator.ModeKeys
    params):  # Additional configuration
    pass
# Build a DNN with 2 hidden layers and 10 nodes in each hidden layer.
classifier = tf.estimator.DNNClassifier(
    feature_columns=my_feature_columns,
    # Two hidden layers of 10 nodes each.
    hidden_units=[10, 10],
    # The model must choose between 3 classes.
    n_classes=3)
